﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class caseadd : System.Web.UI.Page
{
    public string SqlClass = "";
	public string strygcname,strygcheckcode,strbgcname,strbgcheckcode;
	public string strtel,strcasecode,strcasetitle,strjudge,straddtime,strccontent,strcstatus;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"]==null)
		{
			Response.Write("<script>alert('你没有管理员权限，禁止访问！');history.back();</script>");
		}
		if (!Page.IsPostBack)
        {
            casecode.Text = "(2010)杭西民初字第00001号";
            addtime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            //ygcheckcode.Text = getnumber();
			//bgcheckcode.Text = getnumberbg();
		
			DataSet dss = Socut.Data.ExecuteDataSet("select judgename,id from web_judge where isused=0 order by orderno");
				this.DropDownList1.DataSource=dss.Tables[0].DefaultView; 
				this.DropDownList1.DataTextField="judgename"; 
				this.DropDownList1.DataValueField = "id"; 
				this.DropDownList1.DataBind();

                DataSet ds = Socut.Data.ExecuteDataSet("select top 1 * from web_judge order by id");
                tel.Text = ds.Tables[0].Rows[0]["tel"].ToString();
        }
    }

        protected void Button1_Click(object sender, EventArgs e)
        {
                strcasetitle=casetitle.Text.ToString();
				strcasecode=casecode.Text.ToString();
				strygcname=ygcname.Text.ToString();
				strygcheckcode=ygcheckcode.Text.ToString();
				strbgcname=bgcname.Text.ToString();
				strbgcheckcode=bgcheckcode.Text.ToString();
                strjudge = DropDownList1.SelectedItem.ToString();
				strtel=tel.Text.ToString();
				straddtime=Convert.ToDateTime(addtime.Text.ToString()).ToShortDateString();
				strccontent=ccontent.Text.ToString();
				strcstatus=cstatus.SelectedValue.ToString();

				try
                {
                    Socut.Data.ExecuteNonQuery("insert into [web_case] (casetitle,casecode,ygname,ygcheckcode,bgname,bgcheckcode,judge,tel,addtime,content,status) values('" + strcasetitle + "','" + strcasecode +"','" + strygcname + "','" + strygcheckcode +"','" + strbgcname + "','" + strbgcheckcode +"','" + strjudge + "','" + strtel +"','" + straddtime + "','" + strccontent +"'," + strcstatus + ")");
                    Response.Write("<script>alert('恭喜，案件添加成功！');location.href='case.aspx';</script>");
					Response.End();
                }
                catch (Exception Err)
                {
                    Response.Write("<script>alert('操作错误2');history.back();</script>");
					Response.End();
                }

            //Response.Write(AllLimit);
        }


    public string sjname()
    {

        string sj = null;
        sj = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
        return sj;


    }

    public string getnumber()
    {
        string id = "";
        Random ro = new Random(unchecked((int)DateTime.Now.Ticks));
        //id = "YG" + DateTime.Now.ToString("yyyyMMddss") + ro.Next(0, 999).ToString("000");
		id = DateTime.Now.ToString("ss") + ro.Next(0, 99).ToString("00");
        return id;
    }
	
	public string getnumberbg()
    {
        string id = "";
        Random ro = new Random(unchecked((int)DateTime.Now.Ticks));
        //id = "BG" + DateTime.Now.ToString("yyyyMMddss") + ro.Next(0, 999).ToString("000");
		id = DateTime.Now.ToString("mmss");
        return id;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        tel.Text = checktel(DropDownList1.SelectedItem.ToString());
    }
    public string checktel(string strjudge)
    {
        string judgestr = strjudge;
        DataSet ds = Socut.Data.ExecuteDataSet("select * from web_judge where judgename='" + judgestr + "'");
        string strtel = ds.Tables[0].Rows[0]["tel"].ToString();
        return strtel;
    }
}
